require([ "esri/map", "esri/graphic", "esri/geometry/Point",
		"esri/graphicsUtils", "esri/SpatialReference",
		"esri/tasks/GeometryService", "esri/tasks/LengthsParameters",
		"esri/tasks/AreasAndLengthsParameters", "esri/tasks/FindTask",
		"esri/tasks/FindParameters", "esri/tasks/query",
		"esri/tasks/QueryTask", "esri/tasks/StatisticDefinition",
		"esri/layers/ArcGISTiledMapServiceLayer",
		"esri/layers/ArcGISDynamicMapServiceLayer", "esri/layers/FeatureLayer",
		"esri/tasks/ClassBreaksDefinition", "esri/tasks/AlgorithmicColorRamp",
		"esri/geometry/screenUtils", "esri/tasks/GenerateRendererParameters",
		"esri/tasks/GenerateRendererTask", "esri/dijit/OverviewMap",
		"esri/dijit/BasemapGallery", "esri/dijit/Scalebar",
		"esri/symbols/SimpleLineSymbol", "esri/symbols/SimpleFillSymbol",
		"esri/toolbars/draw", "esri/toolbars/edit", "esri/toolbars/navigation",
		"esri/dijit/Measurement", "esri/dijit/PopupTemplate",
		"esri/dijit/Legend", "esri/config", "dojo/parser", "dojo/_base/array", "dojo/_base/connect",
		"dojo/_base/lang", "dojox/encoding/base64", "esri/Color", "dojo/on",
		"dojo/dom-attr", "dojo/dom-class", "dojo/dom-style", "dojo/query",
		"dojo/dom", "dojo/dom-construct", "dijit/registry", "dojo/json",
		"dojo/data/ItemFileReadStore", "dijit/form/FilteringSelect",
		"dgrid/OnDemandGrid", "dgrid/Selection", "dgrid/extensions/Pagination",
		"dojo/store/Observable", "dojo/store/Memory", "dojo/store/Cache",
		"dojo/store/JsonRest", "dojox/charting/Chart",
		"dojox/charting/themes/Bahamation", "dojo/_base/declare",
		"esri/layers/GraphicsLayer", "dijit/dijit-all", // dijit.*
		"dojox/layout/ResizeHandle", "dojox/widget/Dialog",
		"dojox/layout/FloatingPane", "dojo/dnd/Moveable", "dojo/fx",
		"dojox/layout/Dock", "dojox/grid/EnhancedGrid",
		"dojox/grid/enhanced/plugins/GridSource",
		"dojox/grid/enhanced/plugins/Pagination",
		"dojox/grid/enhanced/plugins/CellMerge", "dojox/charting/DataChart",
		"dojo/domReady!" ], function(Map, Graphic, Point, graphicsUtils,
		SpatialReference, GeometryService, LengthsParameters,
		AreasAndLengthsParameters, FindTask, FindParameters, Query, QueryTask,
		StatisticDefinition, ArcGISTiledMapServiceLayer,
		ArcGISDynamicMapServiceLayer, FeatureLayer, ClassBreaksDefinition,
		AlgorithmicColorRamp, screenUtils, GenerateRendererParameters,
		GenerateRendererTask, OverviewMap, BasemapGallery, Scalebar,
		SimpleLineSymbol, SimpleFillSymbol, Draw, Edit, Navigation,
		Measurement, PopupTemplate, Legend, esriConfig, parser, arrayUtils,connect,
		lang, base64, Color, on, domAttr, domClass, domStyle, query, dom,
		domConstruct, registry, JSON, ItemFileReadStore, FilteringSelect, Grid,
		Selection, Pagination, Observable, Memory, Cache, JsonRest, Chart,
		Bahamation, declare) {
	var highlightSymbol = new esri.symbol.SimpleLineSymbol(
			esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([ 78, 171,
					214 ]), 4);
	var highlightFillSymbol = new SimpleFillSymbol(
			SimpleFillSymbol.STYLE_SOLID,
			new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([ 111,
					0, 255 ]), 2), new Color([ 111, 0, 255, 0.15 ]));
	var map = ssmap.map;
	// ** 左边树结构右键查询
	ssmap.createStatisticsMenu = function createStatisticsMenu() {
		function fLocateAreaClick() {
			ssmap.cleanAll();
			var tn = dijit.byNode(pMenu.currentTarget);
			pointAreaLocation(tn.item.id[0]);
		}
		function fLocateStreeClick() {
			ssmap.cleanAll();
			var tn = dijit.byNode(pMenu.currentTarget);
			pointStreeLocation(tn.item.id[0]);
		}
		function fLocateDefinedClick() {
			var tn = dijit.byNode(pMenu.currentTarget);
			ssmap.cleanAll();
			ssmap.tb.activate(esri.toolbars.Draw.POLYGON);
			on.once(ssmap.tb, "draw-end", function(evt) {
				ssmap.tb.deactivate();
				pointDeFineLocation(tn.item.id[0], new Graphic(evt.geometry))
			});
		}
		function fSearchClick() {
			ssmap.cleanAll();
			var tn = dijit.byNode(pMenu.currentTarget);
			var arcSearch = registry.byId("tjSearch");
			var deExtent = listfacilityGrid(arcSearch.value);
			deExtent.then(function(object) {
				var extent = unionExtent(object);
				pointDeFineLocation(tn.item.id[0], new Graphic(extent));
				map.setExtent(extent);
				// var geometrys = arrayUtils.map(findResults,
				// function(findResult,index) {
				// return findResult.feature.geometry ;
				// });
				// geometryService.union(geometrys,function (geometry) {
				// pointDeFineLocation(tn.item.id[0],new Graphic(geometry));
				// })
			});

		}
		var pMenu = new dijit.Menu({
			targetNodeIds : [ "tongjTree" ],
			id : "tongjprogMenu",
			selector : ".dijitTreeNode"
		});
		pMenu.addChild(new dijit.MenuItem({
			label : "行政区划",
			iconClass : "dijitIconqh",
			onClick : fLocateAreaClick
		}));
		pMenu.addChild(new dijit.MenuItem({
			label : "镇(街道)",
			iconClass : "dijitIconjd",
			onClick : fLocateStreeClick
		}));
		var form = new dijit.layout.ContentPane({});
		form.addChild(new dijit.form.TextBox({
			id : "tjSearch",
			placeHolder : "道路编号,或者名称"
		}));
		form.addChild(new dijit.form.Button({
			label : "查询",
			iconClass : "dijitIconSearch",
			onClick : fSearchClick
		}));
		var definedMenu = new dijit.Menu({
			parentMenu : pMenu
		});
		definedMenu.addChild(form);
		pMenu.addChild(new dijit.PopupMenuItem({
			label : "道路",
			iconClass : "dijitIcondl",
			popup : definedMenu
		}));
		pMenu.addChild(new dijit.MenuItem({
			label : "自选区域",
			iconClass : "dijitIconzx",
			onClick : fLocateDefinedClick
		}));
		pMenu.startup();
	}
	function pointAreaLocation(cla) {
		 // map.infoWindow.set("popupWindow", false);
		ssmap.progressBarDialog = dojoProgressBar("正在数据分析");
		var searchurl = appConfig.gisPath
				+ "/arcgis/rest/services/fsjt/bj/MapServer/5";
		var queryTask = new QueryTask(searchurl);
		var query = new Query();
		query.returnGeometry = true;
		query.outFields = [ "*" ];
		query.where = " 1= 1";
		// map.graphics.clear();
		queryTask.execute(query, function(featureSet) {
			dojo.forEach(featureSet.features, function(graphic) {
				console.log(cla);
				if (cla == 'CD') {
					map.graphics.add(fcd(graphic));
				}
				else if (cla == 'DB') {
					map.graphics.add(fdb(graphic));
				}
				 else if (cla == 'LW') {
					map.graphics.add(flw(graphic));
				} else if (cla == 'ZXC') {
					map.graphics.add(fzxc(graphic));
				} else if (cla == 'RXD') {
					map.graphics.add(frxd(graphic));
				} else if (cla == 'JTSX') {
					map.graphics.add(fjtsx(graphic));
				} else if (cla == 'QL') {
					map.graphics.add(fql(graphic));
				}
				//map.infoWindow.resize(300, 500);
				map.centerAndZoom(graphic.geometry.getCentroid(), 9);

			});
		});
		
//        var popup = map.infoWindow;
//        //when the selection changes update the side panel to display the popup info for the 
//        //currently selected feature. 
//        connect.connect(popup, "onSelectionChange", function(){
//        //	contSelectedFeature())
//            displayPopupContent(popup.getSelectedFeature());
//        });


	}
	
	
	function pointStreeLocation(cla) {
		ssmap.progressBarDialog = dojoProgressBar("正在数据分析");
		var searchurl = appConfig.gisPath
				+ "/arcgis/rest/services/fsjt/bj/MapServer/4";
		var queryTask = new QueryTask(searchurl);
		var query = new Query();
		query.returnGeometry = true;
		query.outFields = [ "*" ];
		query.where = " 1= 1";
		queryTask.execute(query, function(featureSet) {
			dojo.forEach(featureSet.features, function(graphic) {
				console.log(cla);
				if (cla == 'CD') {
					map.graphics.add(acd(graphic));
				} else if (cla == 'LW') {
					map.graphics.add(alw(graphic));
				} else if (cla == 'ZXC') {
					map.graphics.add(azxc(graphic));
				} else if (cla == 'RXD') {
					map.graphics.add(arxd(graphic));
				} else if (cla == 'JTSX') {
					map.graphics.add(ajtsx(graphic));
				} else if (cla == 'QL') {
					map.graphics.add(aql(graphic));
				}
			//	map.infoWindow.resize(300, 500);
				map.centerAndZoom(graphic.geometry.getCentroid(), 10);
			});
		}, function() {
			ssmap.progressBarDialog && ssmap.progressBarDialog.hide();
		});
	}
	function pointDeFineLocation(cla, graphic) {
		ssmap.progressBarDialog = dojoProgressBar("正在数据分析");
		if (cla == 'CD') {
			map.graphics.add(acd(graphic));
		} else if (cla == 'LW') {
			map.graphics.add(alw(graphic));
		} else if (cla == 'ZXC') {
			map.graphics.add(azxc(graphic));
		} else if (cla == 'RXD') {
			map.graphics.add(arxd(graphic));
		} else if (cla == 'JTSX') {
			map.graphics.add(ajtsx(graphic));
		} else if (cla == 'QL') {
			map.graphics.add(aql(graphic));
		}
		//map.infoWindow.resize(300, 500);
	}
	
	
    function displayPopupContent(feature){
  
		var node = document.createElement('div');
		dojo.body().appendChild(node);
		var floatingPane =dijit.byId("floatingrightPane");
		if(floatingPane) {
			floatingPane.destroyRecursive();
		}
	    var floatingPane = new dojox.layout.FloatingPane({
	    	draggable:true,
	    	closable :true,
	    	resizable:false,
	    	id:"floatingrightPane",
	    	maxable:false,
	    	dockable:false,
	    	refreshOnShow:true,
	    	style:"width:250px; height:348px;padding:1px;z-index: 9999;top: 120px;right:0px;overflow: hidden; "
	      },node);
	      if(feature){
	            var content = feature.getContent();
	            console.debug(content);
	            floatingPane.set("content", content);
	        }  
    }

	// 对地图进行初始化
	function listfacilityGrid(searchText) {
		if (!searchText) {
			return;
		}
		var searchurl = appConfig.gisPath
				+ "/arcgis/rest/services/fsjt/ss/MapServer/";
		var findParams = new FindParameters();
		findParams.returnGeometry = true;
		findParams.layerIds = [ 55 ];
		findParams.searchFields = [ "道路名称", "道路编号" ];
		findParams.searchText = searchText;
		var findTask = new FindTask(searchurl);
		return findTask.execute(findParams);

	}
	function unionExtent(findResults) {
		var extexts = arrayUtils.map(findResults, function(findResult, index) {
			return findResult.feature;
		});
		return graphicsUtils.graphicsExtent(extexts);
	}
	// 设置高亮的模式
	function setGraphicSymbol(graphic) {
		var geometry = graphic.geometry;
		switch (geometry.type) {
		case "point":
			graphic.setSymbol(diseaseSymbol);
			break;
		case "polyline":
			graphic.setSymbol(highlightSymbol);
			break;
		case "polygon":
			graphic.setSymbol(highlightFillSymbol);
			break;
		}
	}
	// ----区划的模糊查询
	function fcd(feature) {
		var distId = feature.attributes["DistId"];
		if (distId) {
			distId = distId.substr(-1, 2);
		}
		var data = {
			"区域名称" : feature.attributes["DistName"],
			"=====":"==============",
			"区域面积(平方米)" : feature.attributes["SHAPE_Area"],
			"长度单位":"米",
			"快速路" : 0,
			"主干道" : 0,
			"次干道" : 0,
			"支路" : 0,
			"道路总长度" : 0
		}
		var query = new Query();
		query.outFields = [ "*" ];
		query.where = " 道路编号  like '_____0" + distId + "____'";
		query.groupByFieldsForStatistics = [ '道路分级' ];
		var statisticDefinition2 = new StatisticDefinition();
		statisticDefinition2.statisticType = "sum";
		query.geometryPrecision = 2;
		statisticDefinition2.onStatisticField = "道路长度";
		statisticDefinition2.outStatisticFieldName = "dlcd";
		query.outStatistics = [ statisticDefinition2 ];
		var queryTask = new QueryTask(appConfig.gisPath
				+ "/arcgis/rest/services/fsjt/ss/MapServer/55");
		queryTask.execute(query, function(result) {
			var dlzc = 0;
			dojo.forEach(result.features, function(feature) {
				dlcd = feature.attributes.dlcd;
				var dlfj = feature.attributes["道路分级"];
				data[dlfj] = dlcd.toFixed(2);
				dlzc = accAdd(dlzc, dlcd);
			});
			data["道路总长度"] = dlzc.toFixed(2);
			ssmap.progressBarDialog && ssmap.progressBarDialog.hide();
		}, function() {
			ssmap.progressBarDialog && ssmap.progressBarDialog.hide();
		});
		var template = new esri.InfoTemplate("路网分布情况","${*}");
		var graphic = new Graphic(feature.geometry, highlightFillSymbol, data,
				template);
		return graphic;
	}
	
	// ----区划的模糊查询
	function fdb(feature) {
		var distId = feature.attributes["DistName"];
		var data = {
			"区域名称" : feature.attributes["DistName"],
			"=====":"==============",
			"区域面积(平方米)" : feature.attributes["SHAPE_Area"],
			"长度单位":"米",
			"公路总长度" : 0,
			"城市道路长度" : 0,
			"道路总长度" : 0
		}
		var query = new Query();
		query.outFields = [ "*" ];
		console.log(distId)
		query.where = " XIANNAME   = '" + distId + "'";
		var statisticDefinition2 = new StatisticDefinition();
		statisticDefinition2.statisticType = "count";
		statisticDefinition2.onStatisticField = "SHPLENGTH";
		statisticDefinition2.outStatisticFieldName = "dlcd";
		query.outStatistics = [ statisticDefinition2 ];
		var dlzc =0;
		var queryTask = new QueryTask(appConfig.gisPath
				+ "/arcgis/rest/services/fsjt/ss/MapServer/37");
		queryTask.execute(query, function(result) {
			dojo.forEach(result.features, function(feature) {
				var dlcd = feature.attributes.dlcd;
				dlzc = accAdd(dlzc, dlcd);
			});
			ssmap.progressBarDialog && ssmap.progressBarDialog.hide();
		}, function() {
			//console.log("大撒旦法大赛阿斯蒂芬")
			ssmap.progressBarDialog && ssmap.progressBarDialog.hide();
		});
		var queryTask = new QueryTask(appConfig.gisPath
				+ "/arcgis/rest/services/fsjt/ss/MapServer/37");
		queryTask.execute(query, function(result) {
			dojo.forEach(result.features, function(feature) {
				var dlcd = feature.attributes.dlcd;
				dlzc = accAdd(dlzc, dlcd);
			});
			ssmap.progressBarDialog && ssmap.progressBarDialog.hide();
		}, function() {
			ssmap.progressBarDialog && ssmap.progressBarDialog.hide();
		});
		var queryTask = new QueryTask(appConfig.gisPath
				+ "/arcgis/rest/services/fsjt/ss/MapServer/38");
		queryTask.execute(query, function(result) {
			dojo.forEach(result.features, function(feature) {
				var dlcd = feature.attributes.dlcd;
				dlzc = accAdd(dlzc, dlcd);
			});
			ssmap.progressBarDialog && ssmap.progressBarDialog.hide();
		}, function() {
			ssmap.progressBarDialog && ssmap.progressBarDialog.hide();
		});
		var queryTask = new QueryTask(appConfig.gisPath
				+ "/arcgis/rest/services/fsjt/ss/MapServer/39");
		queryTask.execute(query, function(result) {
			dojo.forEach(result.features, function(feature) {
				var dlcd = feature.attributes.dlcd;
				dlzc = accAdd(dlzc, dlcd);
			});
			ssmap.progressBarDialog && ssmap.progressBarDialog.hide();
		}, function() {
			ssmap.progressBarDialog && ssmap.progressBarDialog.hide();
		});
		var queryTask = new QueryTask(appConfig.gisPath
				+ "/arcgis/rest/services/fsjt/ss/MapServer/40");
		queryTask.execute(query, function(result) {
			dojo.forEach(result.features, function(feature) {
				var dlcd = feature.attributes.dlcd;
				dlzc = accAdd(dlzc, dlcd);
			});
			ssmap.progressBarDialog && ssmap.progressBarDialog.hide();
		}, function() {
			ssmap.progressBarDialog && ssmap.progressBarDialog.hide();
		});
		var queryTask = new QueryTask(appConfig.gisPath
				+ "/arcgis/rest/services/fsjt/ss/MapServer/41");
		queryTask.execute(query, function(result) {
			dojo.forEach(result.features, function(feature) {
				var dlcd = feature.attributes.dlcd;
				dlzc = accAdd(dlzc, dlcd);
			});
			ssmap.progressBarDialog && ssmap.progressBarDialog.hide();
		}, function() {
			ssmap.progressBarDialog && ssmap.progressBarDialog.hide();
		});
		data["公路总长度"] = dlzc.toFixed(2);
		var template = new esri.InfoTemplate("公路城市道路对比","${*}");
		var graphic = new Graphic(feature.geometry, highlightFillSymbol, data,
				template);
		return graphic;
	}
	
	function flw(feature) {
		var distId = feature.attributes["DistId"];
		if (distId) {
			distId = distId.substr(-1, 2);
		}
		var data = {
			"区域名称" : feature.attributes["DistName"],
			"=====":"==============",
			"面积单位":"平方米",
			"区域面积" : feature.attributes["SHAPE_Area"],
			"快速路面积" : 0,
			"快速路密度" : 0,
			"主干道面积" : 0,
			"主干道密度" : 0,
			"次干道面积" : 0,
			"次干道密度" : 0,
			"支路面积" : 0,
			"支路密度" : 0,
			"道路总面积" : 0,
			"道路总密度" : 0
		}
		var query = new Query();
		query.outFields = [ "*" ];
		query.where = " 道路编号  like '_____0" + distId + "____'";
		query.groupByFieldsForStatistics = [ '道路分级' ];
		var statisticDefinition2 = new StatisticDefinition();
		statisticDefinition2.statisticType = "sum";
		query.geometryPrecision = 2;
		statisticDefinition2.onStatisticField = "道路总面积";
		statisticDefinition2.outStatisticFieldName = "dlcd";
		query.outStatistics = [ statisticDefinition2 ];
		var queryTask = new QueryTask(appConfig.gisPath
				+ "/arcgis/rest/services/fsjt/ss/MapServer/55");
		queryTask.execute(query, function(result) {
			var dlzc = 0;
			dojo.forEach(result.features, function(feature) {
				dlcd = feature.attributes.dlcd;
				var dlfj = feature.attributes["道路分级"];
				data[dlfj+"面积"] = dlcd.toFixed(2);
				data[dlfj+"密度"] = toPercent(accDiv(dlcd,data["区域面积"]),2);
				dlzc = accAdd(dlzc, dlcd);
			});
			data["道路总面积"] = dlzc.toFixed(2);
			data["道路总密度"] = toPercent(accDiv(dlzc,data["区域面积"]),2);
			ssmap.progressBarDialog && ssmap.progressBarDialog.hide();
		}, function() {
			ssmap.progressBarDialog && ssmap.progressBarDialog.hide();
		});
		var template = new esri.InfoTemplate("路网密度情况","${*}");
		var graphic = new Graphic(feature.geometry, highlightFillSymbol, data,
				template);
		return graphic;
	}
	function fzxc(feature) {
		var distId = feature.attributes["DistId"];
		if (distId) {
			distId = distId.substr(-1, 2);
		}
		var data = {
			"区域名称" : feature.attributes["DistName"],
			"=====":"==============",
			"面积单位":"平方米",
			"区域面积" : feature.attributes["SHAPE_Area"],
			"自行车道面积" : 0
		}
		var query = new Query();
		query.outFields = [ "*" ];
		query.where = " 道路编号  like '_____0" + distId + "____'";
		var statisticDefinition2 = new StatisticDefinition();
		statisticDefinition2.statisticType = "sum";
		statisticDefinition2.onStatisticField = "非机动车道";
		statisticDefinition2.outStatisticFieldName = "mj";
		query.outStatistics = [ statisticDefinition2 ];
		var queryTask = new QueryTask(appConfig.gisPath
				+ "/arcgis/rest/services/fsjt/ss/MapServer/55");
		queryTask.execute(query, function(result) {
			dojo.forEach(result.features, function(feature) {
				data["自行车道面积"] = feature.attributes.mj.toFixed(2);
			});
			ssmap.progressBarDialog && ssmap.progressBarDialog.hide();
		}, function() {
			ssmap.progressBarDialog && ssmap.progressBarDialog.hide();
		});
		var template = new esri.InfoTemplate("自行车道情况","${*}");
		var graphic = new Graphic(feature.geometry, highlightFillSymbol, data,
				template);
		return graphic;
	}

	function frxd(feature) {
		var distId = feature.attributes["DistId"];
		if (distId) {
			distId = distId.substr(-1, 2);
		}
		var data = {
			"区域名称" : feature.attributes["DistName"],
			"=====":"==============",
			"面积单位":"平方米",
			"区域面积" : feature.attributes["SHAPE_Area"],
			"人行道面积" : 0
		}
		var query = new Query();
		query.outFields = [ "*" ];
		query.where = " 道路编号  like '_____0" + distId + "____'";
		var statisticDefinition2 = new StatisticDefinition();
		statisticDefinition2.statisticType = "sum";
		statisticDefinition2.onStatisticField = "人行道面积";
		statisticDefinition2.outStatisticFieldName = "mj";
		query.outStatistics = [ statisticDefinition2 ];
		var queryTask = new QueryTask(appConfig.gisPath
				+ "/arcgis/rest/services/fsjt/ss/MapServer/55");
		queryTask.execute(query, function(result) {
			dojo.forEach(result.features, function(feature) {
				data["人行道面积"] = feature.attributes.mj.toFixed(2);
			});
			ssmap.progressBarDialog && ssmap.progressBarDialog.hide();
		}, function() {
			ssmap.progressBarDialog && ssmap.progressBarDialog.hide();
		});
		var template = new esri.InfoTemplate("人行道情况","${*}");
		var graphic = new Graphic(feature.geometry, highlightFillSymbol, data,
				template);
		return graphic;
	}
	function fql(feature) {
		var distId = feature.attributes["DistId"];
		if (distId) {
			distId = distId.substr(-1, 2);
		}
		var data = {
			"区域名称" : feature.attributes["DistName"],
			"桥梁数目" : 0
		}
		var query = new Query();
		query.outFields = [ "*" ];
		query.where = " 道路编号  like '_____0" + distId + "____'";
		var statisticDefinition2 = new StatisticDefinition();
		statisticDefinition2.statisticType = "sum";
		statisticDefinition2.onStatisticField = "桥梁数目";
		statisticDefinition2.outStatisticFieldName = "qlsm";
		var statisticDefinition3 = new StatisticDefinition();
		statisticDefinition3.statisticType = "sum";
		statisticDefinition3.onStatisticField = "人行天桥数";
		statisticDefinition3.outStatisticFieldName = "rxsm";
		query.outStatistics = [ statisticDefinition2 ];
		var queryTask = new QueryTask(appConfig.gisPath
				+ "/arcgis/rest/services/fsjt/ss/MapServer/55");
		queryTask.execute(query, function(result) {
			dojo.forEach(result.features, function(feature) {
				data["桥梁数目"] = feature.attributes.qlsm;
			    //data["人行天桥数"] = feature.attributes.rxsm;
			});
			ssmap.progressBarDialog && ssmap.progressBarDialog.hide();
		}, function() {
			ssmap.progressBarDialog && ssmap.progressBarDialog.hide();
		});
		var template = new esri.InfoTemplate("桥梁情况","${*}");
		var graphic = new Graphic(feature.geometry, highlightFillSymbol, data,
				template);
		return graphic;
	}

	function fjtsx(feature) {
		var distId = feature.attributes["DistId"];
		if (distId) {
			distId = distId.substr(-1, 2);
		}
		var data = {
			"区域名称" : feature.attributes["DistName"],
			"区域面积" : feature.attributes["SHAPE_Area"],
			"交通信号灯" : 0,
			"交通标志个数" : 0,
			"路灯个数" : 0,
			"标线总面积(平方米)" : 0
		}
		var query = new Query();
		query.outFields = [ "*" ];
		query.where = " 道路编号  like '_____0" + distId + "____'";
		var statisticDefinition2 = new StatisticDefinition();
		statisticDefinition2.statisticType = "sum";
		statisticDefinition2.onStatisticField = "交通信号灯";
		statisticDefinition2.outStatisticFieldName = "xhdgs";
		var statisticDefinition3 = new StatisticDefinition();
		statisticDefinition3.statisticType = "sum";
		statisticDefinition3.onStatisticField = "交通标志个";
		statisticDefinition3.outStatisticFieldName = "bzgs";
		var statisticDefinition4 = new StatisticDefinition();
		statisticDefinition4.statisticType = "sum";
		statisticDefinition4.onStatisticField = "标线总面积";
		statisticDefinition4.outStatisticFieldName = "bxmj";
		
		var statisticDefinition5 = new StatisticDefinition();
		statisticDefinition5.statisticType = "sum";
		statisticDefinition5.onStatisticField = "路灯左侧数";
		statisticDefinition5.outStatisticFieldName = "ld1";
		var statisticDefinition6 = new StatisticDefinition();
		statisticDefinition6.statisticType = "sum";
		statisticDefinition6.onStatisticField = "路灯右侧数";
		statisticDefinition6.outStatisticFieldName = "ld2";
		var statisticDefinition7 = new StatisticDefinition();
		statisticDefinition7.statisticType = "sum";
		statisticDefinition7.onStatisticField = "路灯中央分";
		statisticDefinition7.outStatisticFieldName = "ld3";
		query.outStatistics = [ statisticDefinition2, statisticDefinition3,
				statisticDefinition4 ,statisticDefinition5,statisticDefinition6,statisticDefinition7];
		var queryTask = new QueryTask(appConfig.gisPath
				+ "/arcgis/rest/services/fsjt/ss/MapServer/55");
		queryTask.execute(query, function(result) {
			dojo.forEach(result.features, function(feature) {
				data["交通信号灯"] = feature.attributes.xhdgs;
				data["交通标志个数"] = feature.attributes.bzgs;
				data["路灯个数"] = feature.attributes.ld1+feature.attributes.ld2+ feature.attributes.ld3;
				data["标线总面积(平方米)"] = feature.attributes.bxmj.toFixed(2);
			});
			ssmap.progressBarDialog && ssmap.progressBarDialog.hide();
		}, function() {
			ssmap.progressBarDialog && ssmap.progressBarDialog.hide();
		});
		var template = new esri.InfoTemplate("交通管理设施情况","${*}");
		var graphic = new Graphic(feature.geometry, highlightFillSymbol, data,
				template);
		return graphic;
	}
	
	
	// ----区划的地图查询
	function acd(feature) {
		var data = {
			"长度单位":"米",
			"主干道" : 0,
			"次干道" : 0,
			"支路" : 0,
			"道路总长度" : 0
		}
		var query = new Query();
		query.outFields = [ "*" ];
		query.where = "1 = 1 ";
		query.geometry = feature.geometry;
		var queryTask = new QueryTask(appConfig.gisPath
				+ "/arcgis/rest/services/fsjt/ss/MapServer/55");
		var dlcd = 0, zgd = 0, cgd = 0, zl = 0;
		queryTask.execute(query, function(result) {
			dojo.forEach(result.features, function(feature) {
				var dlfj = feature.attributes['道路分级'];
				var cd = feature.attributes['道路长度'];
				if (dlfj == '主干道') {
					zgd = accAdd(zgd, cd);
				} else if (dlfj == '次干道') {
					cgd = accAdd(cgd, cd);
				} else if (dlfj == '支路') {
					zl = accAdd(zl, cd);
				}
				dlcd = zgd + cgd + zl;
			});
			data["道路总长度"] = dlcd.toFixed(2);
			data["主干道"] = zgd.toFixed(2);
			data["次干道"] = cgd.toFixed(2);
			data["支路"] = zl.toFixed(2);
			ssmap.progressBarDialog && ssmap.progressBarDialog.hide();
		});
		
		var template = new esri.InfoTemplate("路网分布情况","${*}");
		var graphic = new Graphic(feature.geometry, highlightFillSymbol, data,
				template);
		return graphic;
	}
	
	function alw(feature) {
		var data = {
			"面积单位":"平方米",
			"主干道" : 0,
			"次干道" : 0,
			"支路" : 0,
			"道路总面积" : 0
		}
		var query = new Query();
		query.outFields = [ "*" ];
		query.where = "1 = 1 ";
		query.geometry = feature.geometry;
		var queryTask = new QueryTask(appConfig.gisPath
				+ "/arcgis/rest/services/fsjt/ss/MapServer/55");
		var dlcd = 0, zgd = 0, cgd = 0, zl = 0;
		queryTask.execute(query, function(result) {
			dojo.forEach(result.features, function(feature) {
				var dlfj = feature.attributes['道路分级'];
				var cd = feature.attributes['道路总面积'];
				if (dlfj == '主干道') {
					zgd = accAdd(zgd, cd);
				} else if (dlfj == '次干道') {
					cgd = accAdd(cgd, cd);
				} else if (dlfj == '支路') {
					zl = accAdd(zl, cd);
				}
				dlcd = zgd + cgd + zl;
			});
			data["道路总面积"] = dlcd.toFixed(2);
			data["主干道"] = zgd.toFixed(2);
			data["次干道"] = cgd.toFixed(2);
			data["支路"] = zl.toFixed(2);
			ssmap.progressBarDialog && ssmap.progressBarDialog.hide();
		});

		var template = new esri.InfoTemplate("路网面积情况","${*}");
		var graphic = new Graphic(feature.geometry, highlightFillSymbol, data,
				template);
		return graphic;
	}
	
	
	function azxc(feature) {
		var data = {
			"面积单位":"平方米",
			"主干道" : 0,
			"次干道" : 0,
			"支路" : 0,
			"非机动车道总面积" : 0
		}
		var query = new Query();
		query.outFields = [ "*" ];
		query.where = "1 = 1 ";
		query.geometry = feature.geometry;
		var queryTask = new QueryTask(appConfig.gisPath
				+ "/arcgis/rest/services/fsjt/ss/MapServer/55");
		var dlcd = 0, zgd = 0, cgd = 0, zl = 0;
		queryTask.execute(query, function(result) {
			dojo.forEach(result.features, function(feature) {
				var dlfj = feature.attributes['道路分级'];
				var cd = feature.attributes['非机动车道'];
				if (dlfj == '主干道') {
					zgd = accAdd(zgd, cd);
				} else if (dlfj == '次干道') {
					cgd = accAdd(cgd, cd);
				} else if (dlfj == '支路') {
					zl = accAdd(zl, cd);
				}
				dlcd = zgd + cgd + zl;
			});
			data["非机动车道总面积"] = dlcd.toFixed(2);
			data["主干道"] = zgd.toFixed(2);
			data["次干道"] = cgd.toFixed(2);
			data["支路"] = zl.toFixed(2);
			ssmap.progressBarDialog && ssmap.progressBarDialog.hide();
		});
		var template = new esri.InfoTemplate("非机动车道面积情况","${*}");
		var graphic = new Graphic(feature.geometry, highlightFillSymbol, data,
				template);
		return graphic;
	}
	
	function arxd(feature) {
		var data = {
				"面积单位":"平方米",
			"主干道" : 0,
			"次干道" : 0,
			"支路" : 0,
			"人行道总面积" : 0
		}
		var query = new Query();
		query.outFields = [ "*" ];
		query.where = "1 = 1 ";
		query.geometry = feature.geometry;
		var queryTask = new QueryTask(appConfig.gisPath
				+ "/arcgis/rest/services/fsjt/ss/MapServer/55");
		var dlcd = 0, zgd = 0, cgd = 0, zl = 0;
		queryTask.execute(query, function(result) {
			dojo.forEach(result.features, function(feature) {
				var dlfj = feature.attributes['道路分级'];
				var cd = feature.attributes['人行道面积'];
				if (dlfj == '主干道') {
					zgd = accAdd(zgd, cd);
				} else if (dlfj == '次干道') {
					cgd = accAdd(cgd, cd);
				} else if (dlfj == '支路') {
					zl = accAdd(zl, cd);
				}
				dlcd = zgd + cgd + zl;
			});
			data["人行道总面积"] = dlcd.toFixed(2);
			data["主干道"] = zgd.toFixed(2);
			data["次干道"] = cgd.toFixed(2);
			data["支路"] = zl.toFixed(2);
			ssmap.progressBarDialog && ssmap.progressBarDialog.hide();
		});
		var template = new esri.InfoTemplate("人行道面积情况","${*}");
		var graphic = new Graphic(feature.geometry, highlightFillSymbol, data,
				template);
		return graphic;
	}
	
	
	function aql(feature) {
		var data = {
			"桥梁数目" : 0,
			"隧道数目" : 0,
			"人行天桥数" : 0,
			"人行天桥有电梯数" : 0
		}
		var query = new Query();
		query.outFields = [ "*" ];
		query.where = "1 = 1 ";
		query.geometry = feature.geometry;
//		var queryTask = new QueryTask(appConfig.gisPath
//				+ "/arcgis/rest/services/fsjt/ss/MapServer/55");
		var qls = 0, sds = 0, rxtqs = 0, tqs = 0;
//		queryTask.execute(query, function(result) {
//			dojo.forEach(result.features, function(feature) {
//				 qls = accAdd(qls,feature.attributes['桥梁数目']);
//				 sds =accAdd(sds,feature.attributes['隧道数目']);
//				 rxtqs = accAdd(rxtqs,feature.attributes['人行天桥数']);
//				 tqs = accAdd(tqs,feature.attributes['人行天桥有电梯数']);
//				
//			});
//			data["桥梁数目"] = qls.toFixed(0);
//			data["隧道数目"] = sds.toFixed(0);
//			data["人行天桥数"] = rxtqs.toFixed(0);
//			data["人行天桥有电梯数"] = tqs.toFixed(0);
//			ssmap.progressBarDialog && ssmap.progressBarDialog.hide();
//		});
		console.log("人行天桥有电梯数");
		var queryTask2 = new QueryTask(appConfig.gisPath
				+ "/arcgis/rest/services/fsjt/ss/MapServer/33");
		queryTask2.executeForCount(query,function(count) {
			data["桥梁数目"] =count;
		})
		var queryTask3 = new QueryTask(appConfig.gisPath
				+ "/arcgis/rest/services/fsjt/ss/MapServer/32");
		queryTask3.executeForCount(query,function(count) {
			data["隧道数目"] =count;
		})
		var queryTask4 = new QueryTask(appConfig.gisPath
				+ "/arcgis/rest/services/fsjt/ss/MapServer/30");
		queryTask4.executeForCount(query,function(count) {
			data["人行天桥数"] =count;
			ssmap.progressBarDialog && ssmap.progressBarDialog.hide();
		})
		var queryTask5 = new QueryTask(appConfig.gisPath
				+ "/arcgis/rest/services/fsjt/ss/MapServer/30");
		var query2 = new Query();
		query2.outFields = [ "*" ];
		query2.where = "总电梯座数  <> '0' ";
		query2.geometry = feature.geometry;
		queryTask5.executeForCount(query2,function(count) {
			data["人行天桥有电梯数"] =count;
		})
			var template = new esri.InfoTemplate("桥隧情况","${*}");
		var graphic = new Graphic(feature.geometry, highlightFillSymbol, data,
				template);
		return graphic;
	}
	
	function ajtsx(feature) {
		var data = {
	
			"交通信号灯" : 0,
			"交通标志个数" : 0,
			"标线总面积" : 0
		}
		var query = new Query();
		query.outFields = [ "*" ];
		query.where = "1 = 1 ";
		query.geometry = feature.geometry;
		var qls = 0, sds = 0, rxtqs = 0, tqs = 0;
		var queryTask = new QueryTask(appConfig.gisPath
				+ "/arcgis/rest/services/fsjt/ss/MapServer/55");
		queryTask.execute(query, function(result) {
			dojo.forEach(result.features, function(feature) {
				data["交通信号灯"] =accAdd(data["交通信号灯"], feature.attributes["交通信号灯"]);
				data["交通标志个数"] =accAdd(data["交通标志个"],  feature.attributes["交通标志个"]);
				data["标线总面积"] = accAdd(data["标线总面积"],  feature.attributes["标线总面积"]);
			});
			ssmap.progressBarDialog && ssmap.progressBarDialog.hide();
		}, function() {
			ssmap.progressBarDialog && ssmap.progressBarDialog.hide();
		});
		var template = new esri.InfoTemplate("交通管理设施情况","${*}");
		var graphic = new Graphic(feature.geometry, highlightFillSymbol, data,
				template);
		return graphic;
	}
});